package com.book.controller;

import com.book.api.jpush.Jpush;
import com.book.entity.Book;
import com.book.format.Result;
import com.book.format.ResultUtil;
import com.book.page.Page;
import com.book.service.BookService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by Mikey on 2017/6/10.
 */
@Controller
public class bookController {

    @Resource
    private BookService bookService;

    @RequestMapping("/bookManage.json")
    public String bookManage(Model model){
        model.addAttribute("main","book-manage.jsp");
        return "/background/index";
    }

    @RequestMapping("/bookBorrow.json")
    public String bookBorrow(){
//        model.addAttribute("main","book-manage.jsp");
        return "/book-borrow";
    }

    @RequestMapping("/getBookList.json")
    @ResponseBody
    public Result getBookList(Page page){
        return bookService.getBookList(page);
    }

    @RequestMapping("/deleteBook.json")
    @ResponseBody
    public Result deleteBook(String b_id){
        return bookService.deleteBook(b_id);
    }

    @RequestMapping("/addOrEditBook.json")
    @ResponseBody
    public Result addOrEditBook(Book book){
        return bookService.addOrEditBook(book);
    }

    @RequestMapping("/jpush.json")
    @ResponseBody
    public Result jpush(String text){
        return ResultUtil.success(Jpush.sendToAllAndroid("通知标题测试","内容标题测试",text,text));
    }
}
